--恐怖酒吧
local kongbujiuba = fk.CreateSkill {
    name = "mcdh_kongbujiuba",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

kongbujiuba:addEffect(fk.TargetSpecified,{
    can_trigger =function(self, event, target, player, data)
        if player:hasSkill(self) and target == player then
                return data.to ~= player and data:isOnlyTarget(data.to)
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = data.to
        player:drawCards(1, self.name)
            if not (player.dead or player:isKongcheng()) then
                local card = room:askForCard(player, 1, 1, false, self.name, false, nil, "#kongbujiuba-push")
                player:addToPile("mcdh_mingting", card, true, self.name)
                local cards = player:getPile("mcdh_mingting")
                if not (to.dead or to:isKongcheng()) then
                    local cids = to:getCardIds("h")
                    local ex = U.askForExchange(to, "mcdh_mingting", "$Hand", cards, cids, "#kongbujiuba-exchange", 1,false)
                    local cardA = table.filter(ex,function(id) return table.contains(cards,id) end)
                    local cardB = table.filter(ex,function(id) return table.contains(cids,id) end)
                    local moveInfos = {}
                    table.insert(moveInfos, {
                        from = player,
                        to = to,
                        ids = cardA,
                        toArea = Card.PlayerHand,
                        moveReason = fk.ReasonExchange,
                        skillName = self.name,
                    })
                    table.insert(moveInfos,{
                        from = to,
                        to = player,
                        ids = cardB,
                        toArea = Card.PlayerSpecial,
                        moveReason = fk.ReasonExchange,
                        skillName = self.name,
                        specialName = "mcdh_mingting"
                    })
                    room:moveCards(table.unpack(moveInfos))
                end
            end
    end
})

kongbujiuba:addEffect(fk.EventPhaseStart,{
    can_trigger =function(self, event, target, player, data)
        if player:hasSkill(self) and target == player then
            return player.phase == Player.Finish
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local dummy = Fk:cloneCard("dilu")
        dummy:addSubcards(player:getPile("mcdh_mingting"))
        room:obtainCard(player, dummy, false, fk.ReasonPrey)
    end
})

Fk:loadTranslationTable {
    ["mcdh_kongbujiuba"] = "恐怖酒吧",
    [":mcdh_kongbujiuba"] = "锁定技,当你使用牌指定其他角色为唯一目标后,你摸一张牌并将一张手牌置于武将牌上,称「酩酊」,然后目标角色须用一张手牌交换你的一张「酩酊」。结束阶段,你获得所有「酩酊」。",
    ["mcdh_mingting"] = "酩酊",
    ["#kongbujiuba-push"] = "恐怖酒吧:将一张手牌置于武将牌上",
    ["#kongbujiuba-exchange"] = "恐怖酒吧",
}

return kongbujiuba